package org.example.computerdesign.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaIgnore;
import cn.hutool.core.util.StrUtil;
import org.example.computerdesign.common.RespBody;
import org.example.computerdesign.common.enums.HttpCode;
import org.example.computerdesign.domain.dto.MedicalCodeD;
import org.example.computerdesign.service.MedicalCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 朱文权
 * */
@RestController
@SaCheckLogin
public class MedicalCodeController {
    @Autowired
    private MedicalCodeService medicalCodeService;
    /**
     *给某病人增添一次医疗代码
     */
    @PostMapping("putCode")
    public RespBody<?> addCodeToP(@RequestBody MedicalCodeD medicalCodeD){
        if(StrUtil.isEmpty(medicalCodeD.getMedicineCode())){
            return RespBody.fail(HttpCode.BAD_REQUEST.getMsg(),HttpCode.BAD_REQUEST.getCode());
        }
        medicalCodeService.putCode(medicalCodeD.getDiagnosticCode(),medicalCodeD.getOperationCode(), medicalCodeD.getMedicineCode(), medicalCodeD.getPid());
        return RespBody.success();
    }
    /**
     * 获取某个病人的历史医疗代码
     * */
    @GetMapping("getMedicalCode")
    public RespBody<?> getMedicalCode(@RequestParam Long pid){
        return RespBody.success(medicalCodeService.getCode(pid));
    }
    /**
     * 删除某个病人的历史医疗代码
     * */
    @PostMapping("deleteCode")
    public RespBody<?> deleteCode(@RequestBody MedicalCodeD medicalCodeD){
        Integer num=medicalCodeService.deleteCode(medicalCodeD.getPid());
        return RespBody.success(String.format("您成功删除掉了%d条数据",num));
    }
    /**
     * 获取药物代码
     * */
    @GetMapping("getMedicineCode")
    public RespBody<?> getMedicine(MedicalCodeD medicalCodeD){
        return RespBody.success(medicalCodeService.getMedicine(medicalCodeD.getDiagnosticCode(),medicalCodeD.getOperationCode(),medicalCodeD.getPid()));
    }
}
